import 'package:flutter/material.dart';
import 'package:flutter_business_2003a/provider/detail_info_provider.dart';
import 'package:flutter_screenutil/screenutil.dart';
import 'package:provider/provider.dart';

class DetailGoodsInfo extends StatelessWidget {
  DetailGoodsInfo({Key? key}) : super(key: key);
  Widget hotTitle = Container(
    margin: const EdgeInsets.only(top: 10.0),
    padding: const EdgeInsets.all(5.0),
    alignment: Alignment.centerLeft,
    decoration: const BoxDecoration(
        color: Colors.white,
        border: Border(bottom: BorderSide(width: 1.0, color: Colors.black12))),
    child: const Text(
      '商品推荐',
      style: TextStyle(color: Colors.pink),
    ),
  );

  Widget _hotWrapList(context) {
    if (Provider.of<DetailInfoProvider>(context)
        .goodsInfo!
        .goodsInfoList!
        .isNotEmpty) {
      List<Widget> listItemWidget = Provider.of<DetailInfoProvider>(context)
          .goodsInfo!
          .goodsInfoList!
          .map((e) {
        return InkWell(
          onTap: () {
            print('点击了商品推荐的单品');
          },
          child: Container(
            width: ScreenUtil().setWidth(372).toDouble(),
            color: Colors.white,
            padding: const EdgeInsets.all(5.0),
            margin: const EdgeInsets.only(bottom: 3.0),
            child: Column(
              children: [
                Image.network(
                  e!.goods_default_icon!,
                  width: ScreenUtil().setWidth(375).toDouble(),
                ),
                Text(
                  e.goods_desc!,
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                  style: TextStyle(
                      color: Colors.pink,
                      fontSize: ScreenUtil().setSp(26).toDouble()),
                ),
                Text('团购价:¥${e.goods_default_price}元'),
                Text(
                  '原价:¥${e.goods_default_price}元',
                  style: const TextStyle(
                      color: Colors.black26,
                      decoration: TextDecoration.lineThrough),
                )
              ],
            ),
          ),
        );
      }).toList();

      return Wrap(
        spacing: 2,
        children: listItemWidget,
      );
    } else {
      return const Center(
        child: Text('加载中'),
      );
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(bottom: ScreenUtil().setHeight(80).toDouble()),
      child: Column(
        children: [hotTitle, _hotWrapList(context)],
      ),
    );
  }
}
